/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ActividadGUI.java
 *
 * Created on 13-mar-2012, 22:46:53
 */

package VISTA;
import MODELO.*;
import CONTROL.*;
/**
 *
 * @author Wilfredo
 */
public class ActividadGUI extends javax.swing.JDialog {
    java.util.ArrayList mia;
    int semaforo = 0;
    /** Creates new form ActividadGUI */
    public ActividadGUI(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        mia = new java.util.ArrayList();
        TransBDEvento.cargar(jComboBox1, mia);
        System.out.println(mia);
        TransBDActividad.consultarTodos();
        if(ServicioBD.siguiente()){
            Actividad x=TransBDActividad.get();
             muevaloalaventana(x);
        }
        else
            System.out.println("OCURRIO ALGO RARO NO ESPERADO");

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
     public void muevaloalaventana(Actividad  m){
        
        jTextField1.setText(m.getNumActi()+"");
        jTextField2.setText(m.getHoraIni()+"");
        jTextField3.setText(m.getHoraFin()+"");
        jTextField4.setText(m.getFechaIni());
        jTextField5.setText(m.getFechaFin());
        jTextField6.setText(m.getDuracion()+"");
        
        jComboBox1.setSelectedItem(m.getEvenNro());
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton7 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField7 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jButton6 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();

        jButton7.setText("jButton7");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("NUMERO ACTIVIDAD");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(26, 32, -1, -1));
        jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 30, 370, -1));

        jLabel2.setText("HORA INICIO");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(26, 80, -1, -1));

        jLabel3.setText("HORA FINAL");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(26, 131, -1, -1));

        jLabel4.setText("FECHA INICIO");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(26, 179, -1, -1));

        jLabel5.setText("FECHA FINAL");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(26, 229, -1, -1));

        jLabel6.setText("DURACION");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(26, 278, -1, -1));
        jPanel1.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 80, 370, -1));
        jPanel1.add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 120, 370, -1));
        jPanel1.add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 170, 370, -1));
        jPanel1.add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 230, 370, -1));

        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });
        jPanel1.add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 270, 370, -1));

        jButton1.setBackground(new java.awt.Color(204, 204, 255));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/35.png"))); // NOI18N
        jButton1.setText("REGRESAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(905, 545, 110, 30));

        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        jPanel1.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 320, 100, -1));

        jTextField7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField7ActionPerformed(evt);
            }
        });
        jPanel1.add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 320, 370, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 60, 1040, 620));

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton6.setBackground(new java.awt.Color(204, 204, 255));
        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/primeroimag1.jpg"))); // NOI18N
        jButton6.setToolTipText("Primero");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, 60, 40));

        jButton8.setBackground(new java.awt.Color(204, 204, 255));
        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/siguiente2.jpg"))); // NOI18N
        jButton8.setToolTipText("Siguiente");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 100, 50, -1));

        jButton9.setBackground(new java.awt.Color(204, 204, 255));
        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/anterior2.jpg"))); // NOI18N
        jButton9.setToolTipText("Anterior");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 150, 50, 30));

        jButton10.setBackground(new java.awt.Color(204, 204, 255));
        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/ultimoimag2.jpg"))); // NOI18N
        jButton10.setToolTipText("Ultimo");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton10, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 210, 60, 40));

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(1040, 60, 90, 620));

        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/13.png"))); // NOI18N
        jButton2.setText("Adicionar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 100, 40));

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/44.png"))); // NOI18N
        jButton3.setText("Modificar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 10, -1, 40));

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Borrar.png"))); // NOI18N
        jButton4.setText("Borrar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 10, 120, 40));

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/42.png"))); // NOI18N
        jButton5.setText("Buscar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 10, 110, 40));

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1130, 60));
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(521, 52, 36, 33));

        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel7.setText("GESTION DE INFORMACION ACTIVIDAD");
        jPanel4.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        getContentPane().add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 680, 1130, 40));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        String scodigo = jTextField1.getText();
        int codigo  = Integer.parseInt(scodigo);
        String ehoraIni  = jTextField2.getText();
        int horaIni = Integer.parseInt(ehoraIni);
        String ehoraFin = jTextField3.getText();
        int horaFin = Integer.parseInt(ehoraFin);
        String fechaIni = jTextField4.getText();
        String fechaFin = jTextField5.getText();
        String fduracion = jTextField6.getText();
        int duracion = Integer.parseInt(fduracion);
        String scodEvento =(String)jComboBox1.getSelectedItem();
        int evenNro=Integer.parseInt(scodigo);
        Actividad  ci=new Actividad(codigo,horaIni,horaFin,fechaIni,fechaFin,duracion,evenNro);
        int n=jComboBox1.getSelectedIndex();
        String NombreEvento= (String)mia.get(n);
        jTextField7.setText(NombreEvento);
        if(TransBDActividad.buscar(codigo)){
           javax.swing.JOptionPane.showMessageDialog(this, "ACTIVIDAD YA EXISTE");
           return;
        }
        if(TransBDActividad.adicionar(ci))
         javax.swing.JOptionPane.showMessageDialog(this, "ACTIVIDAD  INGRESADA EXITOSAMENTE");
        else
           javax.swing.JOptionPane.showMessageDialog(this, "ACTIVIDAD NO SE PUDO ADICIONAR");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        String scodigo = jTextField1.getText();
        int codigo  = Integer.parseInt(scodigo);
        String ghoraIni  = jTextField2.getText();
        int horaIni = Integer.parseInt(ghoraIni);
        String ghoraFin  = jTextField3.getText();
        int horaFin = Integer.parseInt(ghoraFin);
        String fechaIn  = jTextField4.getText();
        String fechaFin  = jTextField5.getText();
        String kduracion  = jTextField6.getText();
        int duracion = Integer.parseInt(kduracion);
        String codEvento =(String)jComboBox1.getSelectedItem();
        int evenNro=Integer.parseInt(scodigo);
        Actividad  ci=new Actividad(codigo,horaIni,horaFin,fechaIn,fechaFin,duracion,evenNro);
        int n=jComboBox1.getSelectedIndex();
        String NombreEvento= (String)mia.get(n);
        jTextField7.setText(NombreEvento);
        if(!TransBDActividad.buscar(codigo)){
           javax.swing.JOptionPane.showMessageDialog(this, "ACTIVIDAD NO EXISTE");
           return;
        }
        if(TransBDActividad.modificar(ci))
         javax.swing.JOptionPane.showMessageDialog(this, "ACTIVIDAD  MODIFICADA EXITOSAMENTE");
        else
           javax.swing.JOptionPane.showMessageDialog(this, "ACTIVIDAD NO SE PUDO MODIFICAR");
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        String scodigo = jTextField1.getText();
    int codigo = Integer.parseInt(scodigo);
     if (TransBDActividad.buscar(codigo)){
         TransBDActividad.borrar(codigo);
         System.out.println("ACTIVIDAD BORRADA CON EXITO");
     }
     else
           javax.swing.JOptionPane.showMessageDialog(this, "NO EXISTE LA ACTIVIDAD ANIMAL");
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        String scodigo = jTextField1.getText();
    int codigo = Integer.parseInt(scodigo);
  if (TransBDActividad.buscar(codigo)){
       Actividad x= TransBDActividad.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO LO ENCONTRO");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO LO ENCONTRO");
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
        if (ServicioBD.primero()){
       Actividad x= TransBDActividad.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        // TODO add your handling code here:
        if (ServicioBD.siguiente()){
       Actividad x= TransBDActividad.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        // TODO add your handling code here:
        if (ServicioBD.anterior()){
       Actividad x= TransBDActividad.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        // TODO add your handling code here:
        if (ServicioBD.ultimo()){
       Actividad x= TransBDActividad.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
        if(semaforo==1){
    int n=jComboBox1.getSelectedIndex();
        String NombreEvento= (String)mia.get(n);
        jTextField7.setText(NombreEvento);

}
    semaforo = 1;
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField7ActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ActividadGUI dialog = new ActividadGUI(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    // End of variables declaration//GEN-END:variables

}
